<!--
 * @Author: 詹真琦(legendryztachi@gmail.com)
 * @Date: 2022-05-17 11:24:59
 * @LastEditors: 詹真琦(legendryztachi@gmail.com)
 * @LastEditTime: 2022-10-31 15:37:37
 * @FilePath: \code\ctp-static-portal-front\src\views\loginPrePortal\main.vue
 * @Description: 老页面修改数据位置：getDataAndRenderSection(_parameter, _extParameter, retryCount)
-->
<template>
  <Layout
    :currentSpaceId="currentSpaceId"
    :row-data="mainAreaData"
    :theme-data="themeData"
    :space-data="spaceList"
    ref="layout"
  />
</template>

<script>
  import emitter from '@/utils/emitter';
  import transformData from './transform-data';

  // 引入模板
  import Layout from '../pagelayout';

  // iframe地址前缀
  window.urlPreStr = _hostAddr + _loginCtxPath;

  export default {
    name: 'PortalApp',
    components: {
      Layout
    },
    data() {
      let themeData = vPortal.themeHotspots;
      let spaceData = vPortal.space;
      return {
        mainAreaData: [],
        themeData: themeData,
        spaceList: spaceData,
        currentSpaceId: vPortal.allSpaceSectionData ? vPortal.allSpaceSectionData[0] : ''
      };
    },
    created() {
      this.setCurrentSpaceData(this.currentSpaceId);
      emitter.subscribe('changeSpace', ({ id }) => {
        //登录按钮置为true
        this.$refs.layout.setShowLoginBtn();

        // 优先使用空间设置，spaceHotspots-空间个性化设置，portalHotspots-公共门户设置
        // 如果允许用户自定义关闭，spaceHotspots返回的应该是公共门户设置
        this.themeData = vPortal.spaceHotspots[id]
          ? vPortal.spaceHotspots[id]
          : vPortal.portalHotspots;

        this.setCurrentSpaceData(id);
      });
    },
    methods: {
      /**
       * @description: 获取并设置当前空间数据
       * @return {*}
       */
      setCurrentSpaceData(id) {
        $.getJSON(`${_basePath}/archive/portal/${id}/spaceData_${id}.js`, (data) => {
          if (!Array.isArray(data)) {
            data = eval(data);
          }
          this.mainAreaData = null;
          this.mainAreaData = transformData(data);
          emitter.publish('changeSpaceAfter');
        });
      }
    }
  };
</script>
<style>
  /* chrome下滚动条样式 */
  ::-webkit-scrollbar-track-piece {
    width: 8px;
    background-color: #f5f5f5;
    border-radius: 6px;
  }

  ::-webkit-scrollbar {
    width: 8px !important;
    height: 8px !important;
  }

  ::-webkit-scrollbar-thumb {
    height: 50px;
    background: #bec7d5;
    border-radius: 6px;
  }

  ::-webkit-scrollbar-thumb:hover {
    background: #91a0b5;
  }

  /* .bgImage { */

  /*    background-image: url("/static/images/spaceBg/bg-img.jpg"); */

  /*    background-size: 100% 100%; */

  /*    background-repeat: no-repeat; */

  /*    background-attachment: fixed; */

  /*    will-change: margin-top, top; */

  /* } */
</style>
